{{extend '../_layouts/home.html'}}

{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  <div class="row">
    <div class="col-md-5">
      <form id="post_topic">
        <div class="form-group">
           <h3>编辑问题</h3>
          <label for="exampleInputEmail1">标题</label>
          <input type="text" class="form-control" id="exampleInputEmail1" placeholder="请输入标题" name="title" value="{{topic.title}}">
          <input type="hidden" class="form-control" id="exampleInputEmail1" placeholder="请输入标题" name="id" value="{{topic._id}}">
        </div>
        <div class="form-group">
          <label for="exampleInputPassword1">内容</label>
          <textarea class="form-control" rows="3" name="topic">{{topic.topic}}</textarea>
        </div>
        <button  type="submit" class="btn btn-default">确认提交</button>
      </form>
    </div>
  </div>
</section>
<br>
{{/block}}
{{block 'script'}}
<script>

$('#post_topic').on('submit', function (e) {
      e.preventDefault()
      var formData = $(this).serialize()
      $.ajax({
        url: '/user/topic/edit',
        type: 'post',
        data: formData,
        dataType: 'json',
        success: function (data) {
          var err_code = data.err_code
          if (err_code === 0) {
            // 发表topic 成功
            $(".modal-content .modal-body").html(data.message);
            $("#myModal").trigger('click');
            window.setTimeout(function(){
              window.location.href = '/'
            }, 2000);
          } else if (err_code === 1) {
            $(".modal-content .modal-body").html(data.message);
            $("#myModal").trigger('click');
          } else if (err_code === 500) {
            window.alert('服务器忙，请稍后重试！')
          }
        }
      })
    })
</script>
{{/block}}

